<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			// 改变函数内 this 指向，js 提供了三种方法，call() apply() bind()

			// 1. call()
			const obj = {
				name: 'vae',
			};
			function fn(a, b) {
				console.log(this);
				console.log(a + b);
			}
			fn.call(obj, 1, 2);
			// call 既可以调用函数，又可以改变函数内部 this 的指向
			// call 主要作用是可以实现继承
			function Father(uname, age, gender) {
				this.uname = uname;
				this.age = age;
				this.gender = gender;
			}
			function Son(uname, age, gender) {
				Father.call(this, uname, age, gender);
			}
			let son = new Son('vae', 35, 'male');
			console.log(son);
		</script>
	</body>
</html>
